﻿using AutoMapper;

using BCVP.Net8.IService;
using BCVP.Net8.Model.Models;
using BCVP.Net8.Model.ViwModels;
using BCVP.Net8.Repository;
using BCVP.Net8.Repository.Base;

namespace BCVP.Net8.Service
{
    public class BookService : BaseService<Book, BookViewModel>, IBookService
    {
        private readonly IBaseRepository<Book> _dal;
        private readonly IBookRepository _bookDal;
        private IMapper _mapper;
        public BookService(IBaseRepository<Book> baseRepository, IMapper mapper, IBookRepository bookDal) : base(baseRepository, mapper)
        {
            _dal = baseRepository;
            _mapper = mapper;
            _bookDal = bookDal;
        }

        public async Task<BookViewModel> QueryByName(string name)
        {
            await Console.Out.WriteLineAsync($"book_db context id : {base.Db.ContextID}");
            var entity = await _bookDal.QueryByName(name);
            return _mapper.Map<BookViewModel>(entity);
        }
    }
}
